# -*- coding: utf-8 -*-
import scrapy
import re
import os
from XiaChuFang.items import CategoryItem
import sys
#reload(sys)

array = []

class XiachufangSpider(scrapy.Spider):
    name = 'xiachufang'
    allowed_domains = ['xiachufang.com']
    start_urls = ['http://www.xiachufang.com/']

    def parse(self, response):
         pass

class CategorySpider(scrapy.Spider):
    name = 'category'
    allowed_domains = ['xiachufang.com']
    start_urls = ['http://www.xiachufang.com/']

    def parse(self, response):
        Categorys = response.xpath("//div/ul[@class='plain homepage-cats']/li/a[@class='homepage-cat-name']")
        for category in Categorys:
            title = category.xpath("./span/text()").extract_first("")
            suburl = category.xpath("./attribute::href").extract_first("")

            item = CategoryItem()
            item['title'] = title
            item['url'] = "http://www.xiachufang.com" + suburl
            yield item